<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>柯理化函数</title>
</head>
<body>
<script>
    function add(x) {
        var sum = x;
        var tmp = function (y) {
            sum = sum + y;
            return tmp;
        };
        tmp.toString = function () {
            return sum;
        };
        return tmp;
    }
    console.log(add(1)(2)(3));  //6
    console.log(add(1)(2)(3)(4));   //10
</script>
</body>
</html>